class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        // 设置材料检索条件       
        item['Limit'] = parseInt(this.$pagesize.val());
        item['PageIndex'] = this.$pagination.attr("_msh_page") === null ? 0 : parseInt(this.$pagination.attr("_msh_page"));
        item['OrderBy'] = _Instance.orderby;

        item['Begin'] = formatNullInputValue($.trim($("#Begin").val()));
        item['End'] = formatNullInputValue($.trim($("#End").val()));
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);

        return JSON.stringify(item);
    }
    FetchByFilter() {
        this.FetchForPage(1);
    }
    FetchAll() {
        $("#Begin").val("");
        $("#End").val("");
        $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", 1);

        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();

        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            let id = result[i].leaveApplicationId;
            content_01 = '<tr _mash_id="' + id + '" _mash_pid="' + result[i].processInstanceId + '">';
            content_01 += '<td class="column__action"><span title="编辑" class="edit" onclick="_Instance.DoEdit($(this));"><i class="fa-all fa-pencil fa-1"></i></span></td>';
            content_01 += '<td class="column__action"><span title="删除" class="trash" onclick="_Instance.DoDelete($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            let _status = '';
            switch (result[i].flowNodeKey) {
                case "deptleaderaudit":
                    _status = '部门审批';
                    break;
                case "hraudit":
                    _status = '人事审批';
                    break;
                case "modifyapply":
                    _status = '驳回重新申请';
                    break;
                case "reportback":
                    _status = '销假';
                    break;
                default:
                    _status = '<span class="n1">结束</span>';
                    break;
            }
            content_01 += '<td class="column__action"><span title="流程图" class="edit" onclick="_Instance.ShowTraceDiagram($(this));"><i class="fa-all fa-info fa-1"></i></span></td>';
            content_01 += '<td>' + _status + '</td>';
            content_01 += '<td>' + result[i].startTime + '</td>';
            content_01 += '<td>' + result[i].endTime + '</td>';
            content_01 += '<td>' + formatNullData(result[i].leaveApplicationTypeName) + '</td>';
            content_01 += '<td style="border-right:none;">' + formatNullData(result[i].reason) + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
        $('#loading').hide();
    }
    DoInsert() {
        showModal(900, 420, "请假申请", parent.basePath + "/hr/leave_application/edit.html?action=1", null, function ($dialog) {
            let _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
            }
        });
    }
    DoEdit($self) {
        let _node = $self.parent().parent().find("td").eq(3).text();
        let _w = 420;
        switch (_node) {
            case "驳回重新申请":
                _w = 520;
                break;
            case "销假":
                _w = 520;
                break;
            case "结束":
                _w = 520;
                break;
        }
        showModal(900, _w, "请假申请", parent.basePath + "/hr/leave_application/edit.html?action=2&leaveApplicationId=" + $self.parent().parent().attr("_mash_id"), null,
                function ($dialog) {
                    let _exist = $.inArray($dialog, parent.arrDialog);
                    if (_exist >= 0) {
                        parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
                    }
                });
    }
    DoDelete($self) {
        let _params = super.GetFilter(this.$pagination.attr("_msh_page"));
        _params['LeaveApplicationId'] = $self.parent().parent().attr("_mash_id");
        _params['DeletedBy'] = $("#UserId").val();

        super.DoDelete(_params, function (_this, data) {
            if (data > 0) {
                ShowSuccessMessagePanel("删除成功。");
            } else {
                ShowErrorMessagePanel('删除不成功。');
            }
        });
    }
    ShowTraceDiagram($self) {
        showModal(1050, 560, "流程状态图", parent.basePath + "/workflow/process_trace/" + $self.parent().parent().attr("_mash_pid") + "/diagram.html", null, function ($dialog) {
            let _exist = $.inArray($dialog, parent.arrDialog);
            if (_exist >= 0) {
                parent.arrDialog.splice($.inArray($dialog, parent.arrDialog), 1);
            }
        });
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#page-size").val($.cookie("leave_application_list_pagesize") === undefined ? 15 : $.cookie("leave_application_list_pagesize"));

    _Instance = new MyPage(0, null, 0,
            $("#page-size"),
            $("abbr.page_indicator_block, #wrapper__navbar"),
            "leave_application_list_pagesize",
            "leave_application_list_pageindex",
            "leave_application_list_result",
            "/hr/leave_application/fetchForPage.html",
            "/hr/leave_application/delete.html");

    //设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });
    window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });

    _Instance.OnPageLoad();
}

function onPageResize() {
}
